-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add handling of brotli/gzip pre-compressed files #923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Serving pre-compressed brotli/gzip files was not working before, because a file.br.br against the pre-compressed file.br check always returned false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works but it has a consequence - we can no longer directly download the archive. In some situations this might be desirable; it's kind of cool that we have the ability to both preview compressed files as well as download them.
The best thing would be to have the directory listing page provide both options. Clicking the filename should "preview" (i.e. navigate to ./test.jpeg, not ./test.jpeg.br) rather than download, and perhaps a download icon could navigate to ./test.jpeg.br.
This behavior might be desirable sometimes too, but it should be behind a flag because technically it's a regression. I'm going to create a new active branch called better-brotli and merge this there.
| gzippedFile = file.endsWith('gz') ? file : `${file}.gz`; | ||
| brotliFile = file.endsWith('br') ? file : `${file}.br`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful! We need to check for the dot (.) in the file extension too. A common format for comicbook archives (.cbr) also passes .endsWith('br') and would be sent with the header for brotli encoding. I tested this myself and it results in an error in my browser.
| gzippedFile = file.endsWith('gz') ? file : `${file}.gz`; | |
| brotliFile = file.endsWith('br') ? file : `${file}.br`; | |
| gzippedFile = file.endsWith('.gz') ? file : `${file}.gz`; | |
| brotliFile = file.endsWith('.br') ? file : `${file}.br`; |
* feat: add encoding even if .br/.gz specified (#923) * Add handling of brotli/gzip pre-compressed files Serving pre-compressed brotli/gzip files was not working before, because a file.br.br against the pre-compressed file.br check always returned false. * Bump version from 14.1.1 to 14.1.2 * fix: always check the dot This fixes an issue recently introduced where file extensions ending with `br` are handled even when the dot does not immediately preceded. This introduces erroneous an error when trying to access files with other extensions ending with `br`, such as `.cbr`. I meant to merge the previous PR with this fix included but forgot to commit the suggestion I added in the PR review. This was merged to a feature branch so the main branch was not affected. * fix: put new behavior for .br/.gz behind a flag Adds --force-content-encoding flag which must be specified to enable the behavior of including the Content-Encoding header in the response when a .br or .gz file is directly requested in the URL. * test: --force-content-encoding flag Tests whether or not Content-Encoding is present under different cases with and without the --force-content-encoding flag set. * doc: update manpage * sync: package-lock.json --------- Co-authored-by: Andreas Zeitler <[email protected]>
…party#927) * feat: add encoding even if .br/.gz specified (http-party#923) * Add handling of brotli/gzip pre-compressed files Serving pre-compressed brotli/gzip files was not working before, because a file.br.br against the pre-compressed file.br check always returned false. * Bump version from 14.1.1 to 14.1.2 * fix: always check the dot This fixes an issue recently introduced where file extensions ending with `br` are handled even when the dot does not immediately preceded. This introduces erroneous an error when trying to access files with other extensions ending with `br`, such as `.cbr`. I meant to merge the previous PR with this fix included but forgot to commit the suggestion I added in the PR review. This was merged to a feature branch so the main branch was not affected. * fix: put new behavior for .br/.gz behind a flag Adds --force-content-encoding flag which must be specified to enable the behavior of including the Content-Encoding header in the response when a .br or .gz file is directly requested in the URL. * test: --force-content-encoding flag Tests whether or not Content-Encoding is present under different cases with and without the --force-content-encoding flag set. * doc: update manpage * sync: package-lock.json --------- Co-authored-by: Andreas Zeitler <[email protected]>
Serving pre-compressed brotli/gzip files was not working before, because a file.br.br against the pre-compressed file.br check always returned false.
Relevant issues
Adresses Fails to serve Unity/Brotli #844